define(['app'], function(app) {
	'use strict';
	var controller = function controller($scope, Newpropromotions, $window, $timeout, $ionicSlideBoxDelegate, GoPage, $interval, $ionicSideMenuDelegate) {
		$scope.isLoad = false; //可以加载

		$scope.input = new Object();
		$scope.cats = new Array(); //显示的类目
		$scope.input.cat_type = new Array(); //提交的结果{id:"001"}
		$scope.input.nPage = 1;
		//滑动时候触发
		$scope.tabIndex = 0;
		$scope.selectIndex = 0;
		$scope.selectIndex1 = 0;
		$scope.selectIndex2 = 0;
		//画面加载
		$scope.$on('$ionicView.afterEnter', function() {
			var lan = 0; //这是状态栏，只有ios的APP才有
			var tab = 0;
			var bars = document.getElementById("nav-bar-title");
			var bar = ((bars != undefined) ? 44 : 0);
			if(window.cordova && window.cordova.plugins && ionic.Platform.isIOS()) {
				lan = 20;
			}
			//动态设置高度
			var all = $window.innerHeight;
			var Newpropromotions_top1 = document.getElementById("newpropromotions-top1").clientHeight;
			var top2 = document.getElementById("top2").clientHeight;
			//计算滚动条
			$scope.myObj = {
				"height": all - lan - bar - tab - Newpropromotions_top1 -top2 + "px"
			};
			$scope.data_init();
		}, false);
		
		$scope.$on('$ionicView.beforeLeave',function(){
			$interval.cancel($scope.timer);
		})
		
		$scope.set_timer = function(now_time) {
		  $scope.timer = $interval(function() {
				if($scope.datas.act)
					for(var i = 0; i < $scope.datas.act.length; i++) {
						if($scope.datas.act[i].now_time != undefined)
							$scope.datas.act[i].now_time = $scope.datas.act[i].now_time - 1;
						else
							$scope.datas.act[i].now_time = $scope.datas.act[i].end_time - now_time;
						$scope.datas.act[i].formate_time = $scope.formate_time($scope.datas.act[i].now_time);
					}
				if($scope.doing.act)
					for(var i = 0; i < $scope.doing.act.length; i++) {
						if($scope.doing.act[i].now_time != undefined)
							$scope.doing.act[i].now_time = $scope.doing.act[i].now_time - 1;
						else
							$scope.doing.act[i].now_time = $scope.doing.act[i].end_time - now_time;
						$scope.doing.act[i].formate_time = $scope.formate_time($scope.doing.act[i].now_time);
					}
				if($scope.will.act)
					for(var i = 0; i < $scope.will.act.length; i++) {
						if($scope.will.act[i].now_time != undefined)
							$scope.will.act[i].now_time = $scope.will.act[i].now_time - 1;
						else
							$scope.will.act[i].now_time = $scope.will.act[i].start_time - now_time;
						$scope.will.act[i].formate_time = $scope.formate_time($scope.will.act[i].now_time);
					}
				if($scope.giving_all.act)
					for(var i = 0; i < $scope.giving_all.act.length; i++) {
						if($scope.giving_all.act[i].now_time != undefined)
							$scope.giving_all.act[i].now_time = $scope.giving_all.act[i].now_time - 1;
						else
							$scope.giving_all.act[i].now_time = $scope.giving_all.act[i].end_time - now_time;
						$scope.giving_all.act[i].formate_time = $scope.formate_time($scope.giving_all.act[i].now_time);
					}
				if($scope.giving_started.act)
					for(var i = 0; i < $scope.giving_started.act.length; i++) {
						if($scope.giving_started.act[i].now_time != undefined)
							$scope.giving_started.act[i].now_time = $scope.giving_started.act[i].now_time - 1;
						else
							$scope.giving_started.act[i].now_time = $scope.giving_started.act[i].end_time - now_time;
						$scope.giving_started.act[i].formate_time = $scope.formate_time($scope.giving_started.act[i].now_time);
					}
				if($scope.giving_will.act)
					for(var i = 0; i < $scope.giving_will.act.length; i++) {
						if($scope.giving_will.act[i].now_time != undefined)
							$scope.giving_will.act[i].now_time = $scope.giving_will.act[i].now_time - 1;
						else
							$scope.giving_will.act[i].now_time = $scope.giving_will.act[i].start_time - now_time;
						$scope.giving_will.act[i].formate_time = $scope.formate_time($scope.giving_will.act[i].now_time);
					}
				if($scope.notice_all.act)
					for(var i = 0; i < $scope.notice_all.act.length; i++) {
						if($scope.notice_all.act[i].now_time != undefined)
							$scope.notice_all.act[i].now_time = $scope.notice_all.act[i].now_time - 1;
						else
							$scope.notice_all.act[i].now_time = $scope.notice_all.act[i].end_time - now_time;
						$scope.notice_all.act[i].formate_time = $scope.formate_time($scope.notice_all.act[i].now_time);
					}
				if($scope.notice_started.act)
					for(var i = 0; i < $scope.notice_started.act.length; i++) {
						if($scope.notice_started.act[i].now_time != undefined)
							$scope.notice_started.act[i].now_time = $scope.notice_started.act[i].now_time - 1;
						else
							$scope.notice_started.act[i].now_time = $scope.notice_started.act[i].end_time - now_time;
						$scope.notice_started.act[i].formate_time = $scope.formate_time($scope.notice_started.act[i].now_time);
					}
				if($scope.notice_will.act)
					for(var i = 0; i < $scope.notice_will.act.length; i++) {
						if($scope.notice_will.act[i].now_time != undefined)
							$scope.notice_will.act[i].now_time = $scope.notice_will.act[i].now_time - 1;
						else
							$scope.notice_will.act[i].now_time = $scope.notice_will.act[i].start_time - now_time;
						$scope.notice_will.act[i].formate_time = $scope.formate_time($scope.notice_will.act[i].now_time);
					}

			}, 1000)
		}
		$scope.init_time = function(data, now_time) {
			for(var i = 0; i < data.act.length; i++) {
				if(data.act[i].now_time != undefined)
					data.act[i].now_time = data.act[i].now_time - 1;
				else{
					if(data.act_status==1){
						data.act[i].now_time = data.act[i].start_time - now_time;
					}else{
						data.act[i].now_time = data.act[i].end_time - now_time;
					}
				}
				data.act[i].formate_time = $scope.formate_time(data.act[i].now_time);
			}

		}
		$scope.formate_time = function(time) {
			if(time > 0) {
				var day = parseInt(time / (3600 * 24));
				var hour = parseInt((time % (3600 * 24)) / 3600);
				if(hour < 10)
					hour = "0" + hour;
				var min = parseInt((time % 3600) / 60);
				if(min < 10)
					min = "0" + min;
				var second = time % 60;
				if(second < 10)
					second = "0" + second;
				return day + '天' + hour + '小时' + min + '分' + second + '秒';
				console.log(1);
			} else {
				return '0天0小时0分0秒';
			}
		}

		$scope.data_init = function() {
			//新品测试列表
			Newpropromotions.get_test_list(1, '', function(data, now_time) {
				$scope.set_timer(now_time);
				if(data != null) {
					$scope.init_time(data, now_time);
					
					$scope.datas = data;
				} else {
					$scope.datas = new Object();

				}
				$scope.input.nPage = 1;
			});
			Newpropromotions.get_test_list(1, 'started', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.doing = data;
				} else {
					$scope.doing = new Object();

				}
				$scope.input.doing_nPage = 1;
			});
			Newpropromotions.get_test_list(1, 'will', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.will = data;
				} else {
					$scope.will = new Object();

				}
				$scope.input.will_nPage = 1;

			});
			Newpropromotions.get_test_list(1, 'ended', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.ended = data;
				} else {
					$scope.ended = new Object();
				}
				$scope.input.ended_nPage = 1;
			});
			//新品赠送列表
			Newpropromotions.get_giving_list(1, '', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.giving_all = data;
				} else {
					$scope.giving_all = new Object();
				}
				$scope.input.giving_all_nPage = 1;
			});

			Newpropromotions.get_giving_list(1, 'started', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.giving_started = data;
				} else {
					$scope.giving_started = new Object();
				}
				$scope.input.giving_started_nPage = 1;
			});

			Newpropromotions.get_giving_list(1, 'will', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.giving_will = data;
				} else {
					$scope.giving_will = new Object();
				}
				$scope.input.giving_will_nPage = 1;
			});

			Newpropromotions.get_giving_list(1, 'ended', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.giving_ended = data;
				} else {
					$scope.giving_ended = new Object();
				}
				$scope.input.giving_ended_nPage = 1;
			});
			//新品广告列表
			Newpropromotions.get_notice_list(1, '', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.notice_all = data;
				} else {
					$scope.notice_all = new Object();
				}
				$scope.input.notice_all_nPage = 1;
			});
			Newpropromotions.get_notice_list(1, 'started', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.notice_started = data;
				} else {
					$scope.notice_started = new Object();
				}
				$scope.input.notice_started_nPage = 1;
			});
			Newpropromotions.get_notice_list(1, 'will', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.notice_will = data;
				} else {
					$scope.notice_will = new Object();
				}
				$scope.input.notice_will_nPage = 1;
			});
			Newpropromotions.get_notice_list(1, 'ended', function(data, now_time) {
				if(data != null) {
					$scope.init_time(data, now_time);
					$scope.notice_ended = data;
				} else {
					$scope.notice_ended = new Object();
				}
				$scope.input.notice_ended_nPage = 1;
			});
			
		}
		

		//下拉刷新 判断哪个模块进行刷新
		$scope.doRefresh = function() {
			$scope.isLoad = true;
			if($scope.tabIndex == 0) {
				if($scope.selectIndex == 3) {
					Newpropromotions.get_test_list(1, '', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.datas = data;
						} else
							$scope.datas = new Object();
						$scope.input.nPage = 1;

					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				} else if($scope.selectIndex == 0) {
					Newpropromotions.get_test_list(1, 'started', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.doing = data;
							//					$scope.set_timer()
						} else
							$scope.doing = new Object();
						$scope.input.doing_nPage = 1;

					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				} else if($scope.selectIndex == 1) {
					Newpropromotions.get_test_list(1, 'will', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.will = data;
						} else {
							$scope.will = new Object();
						}
						$scope.input.will_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				} else {
					Newpropromotions.get_test_list(1, 'ended', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.ended = data;
						} else
							$scope.ended = new Object();
						$scope.input.ended_nPage = 1;

					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				}
			} else if($scope.tabIndex == 1) {
				if($scope.selectIndex1 == 3) {
					Newpropromotions.get_giving_list(1, '', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.giving_all = data;
						} else {
							$scope.giving_all = new Object();
						}
						$scope.input.giving_all_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else if($scope.selectIndex1 == 0)
					Newpropromotions.get_giving_list(1, 'started', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.giving_started = data;
						} else {
							$scope.giving_started = new Object();
						}
						$scope.input.giving_started_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				else if($scope.selectIndex1 == 1)
					Newpropromotions.get_giving_list(1, 'will', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.giving_will = data;
						} else {
							$scope.giving_will = new Object();
						}
						$scope.input.giving_will_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				else if($scope.selectIndex1 == 2)
					Newpropromotions.get_giving_list(1, 'ended', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.giving_ended = data;
						} else {
							$scope.giving_ended = new Object();
						}
						$scope.input.giving_ended_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
			} else if($scope.tabIndex == 2) {
				if($scope.selectIndex2 == 3) {
					Newpropromotions.get_notice_list(1, '', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.notice_all = data;
						} else {
							$scope.notice_all = new Object();
						}
						$scope.input.notice_all_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else if($scope.selectIndex2 == 0) {
					Newpropromotions.get_notice_list(1, 'started', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.notice_started = data;
						} else {
							$scope.notice_started = new Object();
						}
						$scope.input.notice_started_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else if($scope.selectIndex2 == 1) {
					Newpropromotions.get_notice_list(1, 'will', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.notice_will = data;
						} else {
							$scope.notice_will = new Object();
						}
						$scope.input.notice_will_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else {
					Newpropromotions.get_notice_list(1, 'ended', function(data, now_time) {
						if(data != null) {
							$scope.init_time(data, now_time);
							$scope.notice_ended = data;
						} else {
							$scope.notice_ended = new Object();
						}
						$scope.input.notice_ended_nPage = 1;
					}, function() {
						$scope.$broadcast('scroll.refreshComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				}

			}
		};
		$scope.count_f = null;
		$scope.count_s = null;
		$scope.count_t = null;
		$scope.count_fo = null;
		$scope.count_gf = null;
		$scope.count_gs = null;
		$scope.count_gt = null;
		$scope.count_gfo = null;
		$scope.count_nf = null;
		$scope.count_ns = null;
		$scope.count_nt = null;
		$scope.count_nfo = null;

		//加载更多
		$scope.doRefreshMore = function() {
			$scope.isLoad = true;
			if($scope.tabIndex == 0) {
				if($scope.selectIndex == 0) {
					if($scope.datas.act == undefined) {
						$scope.input.nPage = 0;
					} else if($scope.datas.page.count <= $scope.datas.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.datas.page.count < $scope.input.nPage * 10) {
							$scope.input.nPage -= 1;
							$scope.count_f = $scope.input.nPage * 10;
						} else {
							$scope.count_f = null;
						}
					}
					Newpropromotions.get_test_list($scope.input.nPage + 1, '', function(data, now_time) {
						if(data != null) {
							if($scope.datas.act != undefined) {
								if($scope.count_f != null)
									$scope.datas.act.splice($scope.count_f, $scope.datas.page.count - $scope.count_f);
								$scope.init_time(data, now_time);
								$scope.datas.act = $scope.datas.act.concat(data.act);
								$scope.input.nPage += 1;
							} else {
								$scope.datas = data;
								$scope.input.nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				} else if($scope.selectIndex == 1) {
					if($scope.doing.act == undefined) {
						$scope.input.doing_nPage = 0;
					} else if($scope.doing.page.count <= $scope.doing.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.doing.page.count < $scope.input.doing_nPage * 10) {
							$scope.input.doing_nPage -= 1;
							$scope.count_s = $scope.input.doing_nPage * 10;
						} else {
							$scope.count_s = null;
						}
					}
					Newpropromotions.get_test_list($scope.input.doing_nPage + 1, 'started', function(data, now_time) {
						if(data != null) {
							if($scope.doing.act != undefined) {
								if($scope.count_s != null)
									$scope.doing.act.splice($scope.count_s, $scope.doing.page.count - $scope.count_s);
								$scope.init_time(data, now_time);
								$scope.doing.act = $scope.doing.act.concat(data.act);
								$scope.input.doing_nPage += 1;
							} else {
								$scope.doing = data;
								$scope.input.doing_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				} else if($scope.selectIndex == 2) {
					if($scope.will.act == undefined) {
						$scope.input.will_nPage = 0;
					} else if($scope.will.page.count <= $scope.will.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.will.page.count < $scope.input.will_nPage * 10) {
							$scope.input.will_nPage -= 1;
							$scope.count_t = $scope.input.will_nPage * 10;
						} else {
							$scope.count_t = null;
						}
					}
					Newpropromotions.get_test_list($scope.input.will_nPage + 1, 'will', function(data, now_time) {
						if(data != null) {
							if($scope.will.act != undefined) {
								if($scope.count_t != null)
									$scope.will.act.splice($scope.count_t, $scope.will.page.count - $scope.count_t);
								$scope.init_time(data, now_time);
								$scope.will.act = $scope.will.act.concat(data.act);
								$scope.input.will_nPage += 1;
							} else {
								$scope.will = data;
								$scope.input.will_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				} else {
					if($scope.ended.act == undefined) {
						$scope.input.ended_nPage = 0;
					} else if($scope.ended.page.count <= $scope.ended.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.ended.page.count < $scope.input.ended_nPage * 10) {
							$scope.input.ended_nPage -= 1;
							$scope.count_fo = $scope.input.ended_nPage * 10;
						} else {
							$scope.count_fo = null;
						}
					}
					Newpropromotions.get_test_list($scope.input.ended_nPage + 1, 'ended', function(data, now_time) {
						if(data != null) {
							if($scope.datas.act != undefined) {
								if($scope.count_fo != null)
									$scope.ended.act.splice($scope.count_fo, $scope.ended.page.count - $scope.count_fo);
								$scope.init_time(data, now_time);
								$scope.ended.act = $scope.ended.act.concat(data.act);
								$scope.input.ended_nPage += 1;
							} else {
								$scope.ended = data;
								$scope.input.ended_nPage = 1;
							}
						}
					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					})
				}
			} else if($scope.tabIndex == 1) {
				if($scope.selectIndex1 == 0) {
					if($scope.giving_all.act == undefined) {
						$scope.input.giving_all_nPage = 0;
					} else if($scope.giving_all.page.count <= $scope.giving_all.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.giving_all.page.count < $scope.input.giving_all_nPage * 10) {
							$scope.input.giving_all_nPage -= 1;
							$scope.count_gf = $scope.input.giving_all_nPage * 10;
						} else {
							$scope.count_gf = null;
						}
					}
					Newpropromotions.get_giving_list($scope.input.giving_all_nPage + 1, '', function(data, now_time) {
						if(data != null) {
							if($scope.giving_all.act != undefined) {
								if($scope.count_gf != null)
									$scope.giving_all.act.splice($scope.count_gf, $scope.giving_all.page.count - $scope.count_gf);
								$scope.init_time(data, now_time);
								$scope.giving_all.act = $scope.giving_all.act.concat(data.act);
								$scope.input.giving_all_nPage += 1;
							} else {
								$scope.giving_all = data;
								$scope.input.giving_all_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else if($scope.selectIndex1 == 1) {
					if($scope.giving_started.act == undefined) {
						$scope.input.giving_started_nPage = 0;
					} else if($scope.giving_started.page.count <= $scope.giving_started.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.giving_started.page.count < $scope.giving_started_nPage * 10) {
							$scope.input.giving_started_nPage -= 1;
							$scope.count_gs = $scope.input.giving_started_nPage * 10;
						} else {
							$scope.count_gs = null;
						}
					}
					Newpropromotions.get_giving_list($scope.input.giving_started_nPage + 1, 'started', function(data, now_time) {
						if(data != null) {
							if($scope.giving_started.act != undefined) {
								if($scope.count_gs != null)
									$scope.giving_started.act.splice($scope.count_gs, $scope.giving_started.page.count - $scope.count_gs);
								$scope.init_time(data, now_time);
								$scope.giving_started.act = $scope.giving_started.act.concat(data.act);
								$scope.input.giving_started_nPage += 1;
							} else {
								$scope.giving_started = data;
								$scope.input.giving_started_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else if($scope.selectIndex1 == 2) {
					if($scope.giving_will.act == undefined) {
						$scope.input.giving_will_nPage = 0;
					} else if($scope.giving_will.page.count <= $scope.giving_will.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.giving_will.page.count < $scope.giving_will_nPage * 10) {
							$scope.input.giving_will_nPage -= 1;
							$scope.count_gt = $scope.input.giving_will_nPage * 10;
						} else {
							$scope.count_gt = null;
						}
					}
					Newpropromotions.get_giving_list($scope.input.giving_will_nPage + 1, 'will', function(data, now_time) {
						if(data != null) {
							if($scope.giving_will.act != undefined) {
								if($scope.count_gt != null)
									$scope.giving_will.act.splice($scope.count_gt, $scope.giving_will.page.count - $scope.count_gt);
								$scope.init_time(data, now_time);
								$scope.giving_will.act = $scope.giving_will.act.concat(data.act);
								$scope.input.giving_will_nPage += 1;
							} else {
								$scope.giving_will = data;
								$scope.input.giving_will_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else {
					if($scope.giving_ended.act == undefined) {
						$scope.input.giving_ended_nPage = 0;
					} else if($scope.giving_ended.page.count <= $scope.giving_ended.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.giving_ended.page.count < $scope.giving_ended_nPage * 10) {
							$scope.input.giving_ended_nPage -= 1;
							$scope.count_go = $scope.input.giving_ended_nPage * 10;
						} else {
							$scope.count_go = null;
						}
					}
					Newpropromotions.get_giving_list($scope.input.giving_ended_nPage + 1, 'ended', function(data, now_time) {
						if(data != null) {
							if($scope.giving_ended.act != undefined) {
								if($scope.count_go != null)
									$scope.giving_ended.act.splice($scope.count_go, $scope.giving_ended.page.count - $scope.count_go);
								$scope.init_time(data, now_time);
								$scope.giving_ended.act = $scope.giving_ended.act.concat(data.act);
								$scope.input.giving_ended_nPage += 1;
							} else {
								$scope.giving_ended = data;
								$scope.input.giving_ended_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				}
			} else if($scope.tabIndex == 2) {
				if($scope.selectIndex2 == 0) {
					if($scope.notice_all.act == undefined) {
						$scope.input.notice_all_nPage = 0;
					} else if($scope.notice_all.page.count <= $scope.notice_all.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.notice_all.page.count < $scope.notice_all_nPage * 10) {
							$scope.input.notice_all_nPage -= 1;
							$scope.count_nf = $scope.input.notice_all_nPage * 10;
						} else {
							$scope.count_nf = null;
						}
					}
					Newpropromotions.get_notice_list($scope.input.notice_all_nPage + 1, '', function(data, now_time) {
						if(data != null) {
							if($scope.notice_all.act != undefined) {
								if($scope.count_nf != null)
									$scope.notice_all.act.splice($scope.count_nf, $scope.notice_all.page.count - $scope.count_nf);
								$scope.init_time(data, now_time);
								$scope.notice_all.act = $scope.notice_all.act.concat(data.act);
								$scope.input.notice_all_nPage += 1;
							} else {
								$scope.notice_all = data;
								$scope.input.notice_all_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else if($scope.selectIndex2 == 1) {
					if($scope.notice_started.act == undefined) {
						$scope.input.notice_started_nPage = 0;
					} else if($scope.notice_started.page.count <= $scope.notice_all.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.notice_started.page.count < $scope.notice_started_nPage * 10) {
							$scope.input.notice_started_nPage -= 1;
							$scope.count_ns = $scope.input.notice_started_nPage * 10;
						} else {
							$scope.count_ns = null;
						}
					}
					Newpropromotions.get_notice_list($scope.input.notice_started_nPage + 1, '', function(data, now_time) {
						if(data != null) {
							if($scope.notice_started.act != undefined) {
								if($scope.count_ns != null)
									$scope.notice_started.act.splice($scope.count_ns, $scope.notice_started.page.count - $scope.count_ns);
								$scope.init_time(data, now_time);
								$scope.notice_started.act = $scope.notice_started.act.concat(data.act);
								$scope.input.notice_started += 1;
							} else {
								$scope.notice_started = data;
								$scope.input.notice_started = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else if($scope.selectIndex2 == 2) {
					if($scope.notice_wil.act == undefined) {
						$scope.input.notice_will_nPage = 0;
					} else if($scope.notice_wil.page.count <= $scope.notice_wil.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.notice_wil.page.count < $scope.notice_will_nPage * 10) {
							$scope.input.notice_will_nPage -= 1;
							$scope.count_nt = $scope.input.notice_will_nPage * 10;
						} else {
							$scope.count_nt = null;
						}
					}
					Newpropromotions.get_notice_list($scope.input.notice_will_nPage + 1, '', function(data, now_time) {
						if(data != null) {
							if($scope.notice_wil.act != undefined) {
								if($scope.count_nt != null)
									$scope.notice_wil.act.splice($scope.count_nt, $scope.notice_wil.page.count - $scope.count_nt);
								$scope.init_time(data, now_time);
								$scope.notice_wil.act = $scope.notice_wil.act.concat(data.act);
								$scope.input.notice_will_nPage += 1;
							} else {
								$scope.notice_wil = data;
								$scope.input.notice_will_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				} else {
					if($scope.notice_ended.act == undefined) {
						$scope.input.notice_ended_nPage = 0;
					} else if($scope.notice_ended.page.count <= $scope.notice_ended.act.length) {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						if($scope.notice_ended.page.count < $scope.notice_ended_nPage * 10) {
							$scope.input.notice_ended_nPage -= 1;
							$scope.count_nfo = $scope.input.notice_ended_nPage * 10;
						} else {
							$scope.count_nfo = null;
						}
					}
					Newpropromotions.get_notice_list($scope.input.notice_ended_nPage + 1, '', function(data, now_time) {
						if(data != null) {
							if($scope.notice_ended.act != undefined) {
								if($scope.count_nfo != null)
									$scope.notice_ended.act.splice($scope.count_nfo, $scope.notice_ended.page.count - $scope.count_nfo);
								$scope.init_time(data, now_time);
								$scope.notice_ended.act = $scope.notice_ended.act.concat(data.act);
								$scope.input.notice_ended_nPage += 1;
							} else {
								$scope.notice_ended = data;
								$scope.input.notice_ended_nPage = 1;
							}
						}

					}, function() {
						$scope.$broadcast('scroll.infiniteScrollComplete');
						$timeout(function() {
							$scope.isLoad = false;
						}, 1000);
					});
				}

			}
		};

		//新品测试的申请按钮
		$scope.onshow_post_test = function(act_id,act_type,goods_id,product_id) {
			GoPage.go_states("newtest_detail", {
				"act_id": act_id,
				"goods_id":goods_id,
				"product_id":product_id
			});
		};
		$scope.onshow_giving_detail = function(act_id,act_type,goods_id,product_id) {
				GoPage.go_states("newsend_detail", {
					"act_id": act_id,
					"goods_id":goods_id,
					"product_id":product_id
				});
			}
		//新品赠送的申请按钮
		$scope.onshow_notice_detail = function(act_id,act_type,goods_id,product_id) {
			GoPage.go_states("newnotice_detail", {
				"act_id": act_id,
				"goods_id":goods_id,
				"product_id":product_id
			});
		};
		$scope.go_store = function(store_id){
			GoPage.go_states("first", {
				'store_id': store_id
			});
		}
		
		//切换页面
		$scope.activeSlide = function(index) {
			if($scope.tabIndex == 0) {
				$scope.selectIndex = index;
				$ionicSlideBoxDelegate.$getByHandle('tab-handle').slide($scope.selectIndex);
			} else if($scope.tabIndex == 1) {
				$scope.selectIndex1 = index;
				$ionicSlideBoxDelegate.$getByHandle('tab-handle1').slide($scope.selectIndex1);
			} else {
				$scope.selectIndex2 = index;
				$ionicSlideBoxDelegate.$getByHandle('tab-handle2').slide($scope.selectIndex1);
			}
		};
		
		$scope.slideChanged = function(index) {
			$scope.tabIndex = index;
		};
		$scope.activeSlides = function(index) {
			$scope.tabIndex = index;
		};
		
		$scope.onTouch = function() {
			if($scope.tabIndex == 0)
				$ionicSlideBoxDelegate.$getByHandle('tab-handle').enableSlide(false);
			else if($scope.tabIndex == 1)
				$ionicSlideBoxDelegate.$getByHandle('tab-handle1').enableSlide(false);
			else
				$ionicSlideBoxDelegate.$getByHandle('tab-handle2').enableSlide(false);
		};
		//结束点击，立即触发
		$scope.onRelease = function() {
			if($scope.tabIndex == 0)
				$ionicSlideBoxDelegate.$getByHandle('tab-handle').enableSlide(true);
			else if($scope.tabIndex == 1)
				$ionicSlideBoxDelegate.$getByHandle('tab-handle1').enableSlide(true);
			else
				$ionicSlideBoxDelegate.$getByHandle('tab-handle2').enableSlide(true);
		};

	}

	controller.$inject = ['$scope', 'Newpropromotions', '$window', '$timeout', '$ionicSlideBoxDelegate', 'GoPage', '$interval', '$ionicSideMenuDelegate'];
	return app.registerController("newpropromotionsctrl", controller);
});